package com.juanjuan.myproject.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.juanjuan.myproject.entity.Rule;
import com.juanjuan.myproject.service.RuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 规则表 前端控制器
 * </p>
 *
 * @author zhaocun
 * @since 2023-10-25
 */
@RestController
@RequestMapping("/myproject/rule")
@CrossOrigin
public class RuleController {

    @Autowired
    private RuleService ruleService;
    @GetMapping("/export")
    public List<Rule>  test(){
        List<Rule> ruleList = ruleService.getRuleList();
        if (ruleList.size() > 0) {
            String filename = "F:\\规则1.xls";
            // 向Excel中写入数据 也可以通过 head(Class<?>) 指定数据模板
            EasyExcel.write(filename, Rule.class)
                    .sheet("规则信息")
                    .doWrite(ruleList);
        }
        return ruleList;
    }

    @PostMapping("/getRule")
    public List<Rule>  getRule(@RequestBody JSONObject jsonObject){
        List<Rule> i = ruleService.UpdateRule(jsonObject);
        return i;
    }


    @PostMapping("/parms")
    public List<Rule>  getRuleList(@RequestBody JSONObject jsonObject){
        List<Rule>  ruleParms = ruleService.getRuleParms(jsonObject);
        return ruleParms;
    }

    @GetMapping("/isSesusss")
    public List<Rule>  isBoolenIsSecuss(){
        List<Rule>  ruleParms = ruleService.isBoolenIsSecuss();
        return ruleParms;
    }

    @GetMapping("/test")
    public int test11(){
        return 5555;
    }

   @PostMapping("/login")
    public JSONObject login(@RequestBody JSONObject jsonObject){
        jsonObject.put("pass",23748237);
        return jsonObject;
    }
}
